﻿#ifndef H_MY__DXML_H__H
#define	H_MY__DXML_H__H
#include <QDomDocument>

namespace dXml {
	class XmlDataDoc;
	class XmlDataUnit;
	// node 转换到 QDomElement 树
	QDomElement toDocElement(QDomDocument& doc, XmlDataUnit* node);
	// 从 QDomElement 转 node
	void domDocumentToDxmlUnitDoc(dXml::XmlDataUnit* saveToData, QString& outPITarget, QString& outPIData, QDomDocument doc);
	// 存储到 file
	// nodes 多个根节点
	bool save(QList<XmlDataUnit*>& nodes, const QString& file, QDomDocument* qDomDocument = Q_NULLPTR, int tabSize = 4, QDomNode::EncodingPolicy edcoding = QDomNode::EncodingFromDocument);
	/*
	 * saveToDataList 用于存储结果
	 * outPITarget 存储 ProcessingInstructionTarget
	 * outPIData 存储 ProcessingInstructionData
	 */
	bool readXmlFile(XmlDataUnit* saveToData, QString& outPITarget, QString& outPIData, const QString& file);
	/*
	 * 从文本中读取到xml
	 */
	bool readStringToXml(XmlDataUnit* saveToData, QString& outPITarget, QString& outPIData, const QString& strStream);
	/*
	 * QDomNodeList 转 QList<dXml::XmlDataUnit*> 
	 */
	QList<dXml::XmlDataUnit*> docChildRootNodesToXmlDataUnity(const QDomNodeList& domNodes, XmlDataUnit* paren);

	inline const char* getProcessingInstructionTarget( ) {
		static const char* instance = "xml";
		return instance;
	}

	inline const char* getProcessingInstructionData( ) {
		static const char* instance = "version=\"1.0\" encoding=\"UTF-8\"";
		return instance;
	}

	inline const char* getDefaultXmlxStr( ) {
		static const char* instance = "<?xml version=\"1.0\" encoding=\"utf-8\"?><setting><language select=\"zh-CN\"><zh-CN>zh-cn.lg</zh-CN><en>en.lg</en></language></setting>";
		return instance;
	}
}
#endif // H_MY__DXML_H__H
